package top.wu2020.lazy.ws.chat.application.impl;

import org.wu.framework.database.lazy.web.plus.stereotype.LazyApplication;
import top.wu2020.lazy.ws.chat.application.CommunityCommentApplication;
import org.springframework.web.bind.annotation.*;
import org.wu.framework.web.response.Result;
import org.wu.framework.web.response.ResultFactory;
import org.springframework.beans.factory.annotation.Autowired;
import top.wu2020.lazy.ws.chat.domain.model.community.comment.CommunityComment;
import top.wu2020.lazy.ws.chat.application.command.community.comment.CommunityCommentRemoveCommand;
import top.wu2020.lazy.ws.chat.application.command.community.comment.CommunityCommentStoryCommand;
import top.wu2020.lazy.ws.chat.application.command.community.comment.CommunityCommentUpdateCommand;
import top.wu2020.lazy.ws.chat.application.command.community.comment.CommunityCommentQueryListCommand;
import top.wu2020.lazy.ws.chat.application.command.community.comment.CommunityCommentQueryOneCommand;
import top.wu2020.lazy.ws.chat.application.assembler.CommunityCommentDTOAssembler;
import top.wu2020.lazy.ws.chat.application.dto.CommunityCommentDTO;
import java.util.stream.Collectors;
import jakarta.annotation.Resource;
import top.wu2020.lazy.ws.chat.domain.model.community.comment.CommunityCommentRepository;
import java.util.List;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
/**
 * describe community_comment 
 *
 * @author Jia wei Wu
 * @date 2024/05/24 08:52 晚上
 * @see org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyApplicationImpl 
 **/
@LazyApplication
public class CommunityCommentApplicationImpl implements CommunityCommentApplication {

    @Resource
    CommunityCommentRepository communityCommentRepository;
    /**
     * describe 新增
     *
     * @param communityCommentStoryCommand 新增     
     * @return {@link Result<CommunityComment>} 新增后领域对象     
     
     * @author Jia wei Wu
     * @date 2024/05/24 08:52 晚上
     **/

    @Override
    public Result<CommunityComment> story(CommunityCommentStoryCommand communityCommentStoryCommand) {
        CommunityComment communityComment = CommunityCommentDTOAssembler.INSTANCE.toCommunityComment(communityCommentStoryCommand);
        return communityCommentRepository.story(communityComment);
    }
    /**
     * describe 批量新增
     *
     * @param communityCommentStoryCommandList 批量新增     
     * @return {@link Result<List<CommunityComment>>} 新增后领域对象集合     
     
     * @author Jia wei Wu
     * @date 2024/05/24 08:52 晚上
     **/

    @Override
    public Result<List<CommunityComment>> batchStory(List<CommunityCommentStoryCommand> communityCommentStoryCommandList) {
        List<CommunityComment> communityCommentList = communityCommentStoryCommandList.stream().map( CommunityCommentDTOAssembler.INSTANCE::toCommunityComment).collect(Collectors.toList());
        return communityCommentRepository.batchStory(communityCommentList);
    }
    /**
     * describe 更新
     *
     * @param communityCommentUpdateCommand 更新     
     * @return {@link Result<CommunityComment>} 领域对象     
     
     * @author Jia wei Wu
     * @date 2024/05/24 08:52 晚上
     **/

    @Override
    public Result<CommunityComment> updateOne(CommunityCommentUpdateCommand communityCommentUpdateCommand) {
        CommunityComment communityComment = CommunityCommentDTOAssembler.INSTANCE.toCommunityComment(communityCommentUpdateCommand);
        return communityCommentRepository.story(communityComment);
    }

    /**
     * describe 查询单个
     *
     * @param communityCommentQueryOneCommand 查询单个     
     * @return {@link Result<CommunityCommentDTO>} DTO对象     
     
     * @author Jia wei Wu
     * @date 2024/05/24 08:52 晚上
     **/

    @Override
    public Result<CommunityCommentDTO> findOne(CommunityCommentQueryOneCommand communityCommentQueryOneCommand) {
        CommunityComment communityComment = CommunityCommentDTOAssembler.INSTANCE.toCommunityComment(communityCommentQueryOneCommand);
        return communityCommentRepository.findOne(communityComment).convert(CommunityCommentDTOAssembler.INSTANCE::fromCommunityComment);
    }

    /**
     * describe 查询多个
     *
     * @param communityCommentQueryListCommand 查询多个     
     * @return {@link Result<List<CommunityCommentDTO>>} DTO对象     
     
     * @author Jia wei Wu
     * @date 2024/05/24 08:52 晚上
     **/

    @Override
    public Result<List<CommunityCommentDTO>> findList(CommunityCommentQueryListCommand communityCommentQueryListCommand) {
        CommunityComment communityComment = CommunityCommentDTOAssembler.INSTANCE.toCommunityComment(communityCommentQueryListCommand);
        return communityCommentRepository.findList(communityComment)        .convert(communityComments -> communityComments.stream().map(CommunityCommentDTOAssembler.INSTANCE::fromCommunityComment).collect(Collectors.toList())) ;
    }

    /**
     * describe 分页查询多个
     *
     * @param communityCommentQueryListCommand 分页查询多个     
     * @return {@link Result<LazyPage<CommunityCommentDTO>>} 分页DTO对象     
     
     * @author Jia wei Wu
     * @date 2024/05/24 08:52 晚上
     **/

    @Override
    public Result<LazyPage<CommunityCommentDTO>> findPage(int size,int current,CommunityCommentQueryListCommand communityCommentQueryListCommand) {
        CommunityComment communityComment = CommunityCommentDTOAssembler.INSTANCE.toCommunityComment(communityCommentQueryListCommand);
        return communityCommentRepository.findPage(size,current,communityComment)        .convert(page -> page.convert(CommunityCommentDTOAssembler.INSTANCE::fromCommunityComment))            ;
    }

    /**
     * describe 删除
     *
     * @param communityCommentRemoveCommand 删除     
     * @return {@link Result<CommunityComment>}      
     
     * @author Jia wei Wu
     * @date 2024/05/24 08:52 晚上
     **/

    @Override
    public Result<CommunityComment> remove(CommunityCommentRemoveCommand communityCommentRemoveCommand) {
     CommunityComment communityComment = CommunityCommentDTOAssembler.INSTANCE.toCommunityComment(communityCommentRemoveCommand);
     return communityCommentRepository.remove(communityComment);
    }

}